﻿using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SourceStack.TagHelpers
{
    //声明一个自定义的TagHelper：DateTimeTagHelper，在Razor中使用：
    //可以添加属性：asp-showicon
    //再添加属性：asp-only
    [HtmlTargetElement("datetime", Attributes = "showicon,only")]
    public class DateTimeTagHelper : TagHelper
    {
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "small";
            if (context.AllAttributes["only"].Value.ToString() == "date")
            {
                output.Content.SetHtmlContent(DateTime.Now.ToString("yyyy年MM月dd日"));
            }
            else
            {
                output.Content.SetHtmlContent(DateTime.Now.ToString("yyyy年MM月dd日 hh点mm分"));
            }
            if (context.AllAttributes["showicon"].Value.ToString()=="true")
            {
                output.PreContent.SetHtmlContent("<span class='fa fa-calendar'></span>");
            }
            // else nothing
        

            base.Process(context, output);
        }
    }
}
